/* arm7.h -- Useful ARM7 constants
**
** Copyright 2006, Brian Swetland.  All rights reserved.
** See provided LICENSE file or http://frotz.net/LICENSE for details.
*/

#ifndef __ARM7_H__
#define __ARM7_H__

/* status register stuff */

#define PSR_N               0x80000000
#define PSR_C               0x40000000
#define PSR_Z               0x20000000
#define PSR_V               0x10000000

#define PSR_I               0x00000080
#define PSR_F               0x00000040
#define PSR_T               0x00000020

#define PSR_MODE_MASK       0x0000001F
#define PSR_USR             0x00000010
#define PSR_FIQ             0x00000011
#define PSR_IRQ             0x00000012
#define PSR_SVC             0x00000013
#define PSR_ABT             0x00000017
#define PSR_UND             0x0000001B
#define PSR_SYS             0x0000001F

/* EmbeddedICE stuff */
#define IR_EXTEST       0x0
#define IR_SCAN_N       0x2
#define IR_SAMPLE       0x3
#define IR_RESTART      0x4
#define IR_CLAMP        0x5
#define IR_HIGHZ        0x7
#define IR_CLAMPZ       0x9
#define IR_INTEST       0xC
#define IR_IDCODE       0xE
#define IR_BYPASS       0xF

#define ICE_DEBUG_CONTROL     0x00
#define ICE_DEBUG_STATUS      0x01
#define ICE_COMMS_CONTROL     0x04
#define ICE_COMMS_DATA        0x05
#define ICE_WATCH0_ADDR_VALUE 0x10
#define ICE_WATCH0_ADDR_MASK  0x11
#define ICE_WATCH0_DATA_VALUE 0x12
#define ICE_WATCH0_DATA_MASK  0x13
#define ICE_WATCH0_CTRL_VALUE 0x14
#define ICE_WATCH0_CTRL_MASK  0x15
#define ICE_WATCH1_ADDR_VALUE 0x20
#define ICE_WATCH1_ADDR_MASK  0x21
#define ICE_WATCH1_DATA_VALUE 0x22
#define ICE_WATCH1_DATA_MASK  0x23
#define ICE_WATCH1_CTRL_VALUE 0x24
#define ICE_WATCH1_CTRL_MASK  0x25

#define ICE_DEBUG_DBGACK     0x01
#define ICE_DEBUG_DBGRQ      0x02
#define ICE_DEBUG_IFEN       0x04 
#define ICE_DEBUG_INTDIS     0x04 
#define ICE_DEBUG_CGENL      0x08
#define ICE_DEBUG_TBIT       0x10

#define ICE_WATCH_RW         0x001
#define ICE_WATCH_BYTE       0x000
#define ICE_WATCH_HALF       0x002
#define ICE_WATCH_WORD       0x004
#define ICE_WATCH_NOPC       0x008
#define ICE_WATCH_NTRANS     0x010
#define ICE_WATCH_EXTERN     0x020
#define ICE_WATCH_CHAIN      0x040
#define ICE_WATCH_RANGE      0x080
#define ICE_WATCH_ENABLE     0x100

/* opcodes */
#define ARM_NOP             0xE1A00000
#define ARM_MRS_R0_CPSR     0xE10F0000
#define ARM_MRS_R0_SPSR     0xE14F0000
#define ARM_LDR_R1_R0       0xE5901000
#define ARM_STR_R1_R0       0xE4801000

#define ARM_LDR_Rd_Rs(d,s) (0xE5900000 | ((d) << 12) | ((s) << 16))
#define ARM_MOV_Rx_0(x)    (0xE3A00000 | ((x) << 12))
#define ARM_STR_Rx_R14(x)  (0xE58E0000 | ((x) << 12))
#define ARM_LDR_Rx_R14(x)  (0xE59E0000 | ((x) << 12))
#define ARM_LDMIA_LR(mask) (0xE89E0000 | (mask))
#define ARM_STMIA_LR(mask) (0xE88E0000 | (mask))
#define ARM_STMIA_LR_BANG(mask) (0xE8AE0000 | (mask))

#endif
